package com.jwell.panprovider.model

import com.jwell.driverapp.tools.BaseSubscriber
import com.jwell.panprovider.application.App
import com.jwell.panprovider.contract.ProviderRegisterContract
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

/**
 * Created by 76577 on 2018/4/22.
 * 供应预登记
 */
class ProviderRegisterModel : ProviderRegisterContract.Model, BaseModel() {
    override fun checkCarNum(id: String, baseSubscriber: BaseSubscriber) {
        val map = mutableMapOf("id" to id)
        if (App.DEBUG) println("供应商预登记验证车牌" + map.toString())
        getApiStore().checkCarNum(map)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(baseSubscriber)
    }

    override fun checkDriverPhone(id: String, baseSubscriber: BaseSubscriber) {
        val map = mutableMapOf("id" to id)
        if (App.DEBUG) println("供应商预登记验证司机手机号" + map.toString())
        getApiStore().checkDriverPhone(map)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(baseSubscriber)
    }


    override fun appSupplyRegistration(data: RequestData, baseSubscriber: BaseSubscriber) {
        if (App.DEBUG) println("供应商预登记" + data.toString())
        getApiStore().appSupplyRegistration(data)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(baseSubscriber)
    }

    override fun appGetContractDetail(data: Detail, baseSubscriber: BaseSubscriber) {
        if (App.DEBUG) println("供应商预登记获取详情" + data.toString())
        getApiStore().appGetContractDetail(data)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(baseSubscriber)
    }


    //    driverName (string, optional): 司机名称 ,
//    carNum (string, optional): 车牌号 ,
//    driverPhone (string, optional): 司机电话 ,
//    remark (string, optional): 备注 ,
//    mtrlOrderNo (string, optional): 合同号 ,
//    fuelDetailId (integer, optional): 计划明细id ,
//    forwardingUnit (string, optional): 发货单位 ,
    //  receivingUnit (string, optional): 收货单位 ,
    //measurementMethod (integer, optional): 计量方式 1、先重后空 2、先空后重 3、标证除皮 4、只称重车 5、只称空车 = ['1', '2', '3', '4', '5'],
//    id (integer, optional)
    data class RequestData(var driverName: String? = null,
                           var carNum: String? = null,
                           var driverPhone: String? = null,
                           var text_driverPhone: String? = null,
                           var remark: String? = null,
                           var mtrlOrderNo: String? = null,
                           var fuelDetailId: Int? = null,
                           var forwardingUnit: String? = null,
                           var receivingUnit: String? = null,
                           var measurementMethod: Int? = null,
                           var id: Int? = null)

    /**
     * fuelDetailId (integer, optional): 计划明细id ,
    mtrlOrderNo (string, optional): 合同号
     */
    data class Detail(var fuelDetailId: Int? = null,
                      var mtrlOrderNo: String? = null)
}